package pt.our.angemc.parser;

// $ANTLR 3.2 Sep 23, 2009 12:02:23 /home/luis/AnGEMC/src/grammarGrammar/graal.g 2010-05-09 14:39:09

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

public class graalParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "TERMINAL", "NTERMINAL", "ELEMENT", "ALTERNATIVE", "RESERVED", "SIGN", "SEQUENCE", "TERMINALT", "NTERMINALT", "RESERVEDT", "SIGNT", "SEQUENCET", "OTHER", "OTHERT", "ATSIN", "ATSOUT", "ID", "STRING", "DOLARID", "ESC_SEQ", "HEX_DIGIT", "UNICODE_ESC", "OCTAL_ESC", "WS", "':'", "';'", "'returns'", "'['", "','", "']'", "'|'", "'~'", "'('", "')'", "'*'", "'+'", "'?'", "'..'"
    };
    public static final int SIGN=9;
    public static final int DOLARID=22;
    public static final int T__40=40;
    public static final int T__41=41;
    public static final int SIGNT=14;
    public static final int T__29=29;
    public static final int T__28=28;
    public static final int OTHER=16;
    public static final int TERMINAL=4;
    public static final int TERMINALT=11;
    public static final int UNICODE_ESC=25;
    public static final int OCTAL_ESC=26;
    public static final int HEX_DIGIT=24;
    public static final int ATSIN=18;
    public static final int NTERMINALT=12;
    public static final int ID=20;
    public static final int EOF=-1;
    public static final int SEQUENCE=10;
    public static final int T__30=30;
    public static final int T__31=31;
    public static final int T__32=32;
    public static final int WS=27;
    public static final int ESC_SEQ=23;
    public static final int SEQUENCET=15;
    public static final int T__33=33;
    public static final int T__34=34;
    public static final int RESERVED=8;
    public static final int T__35=35;
    public static final int T__36=36;
    public static final int T__37=37;
    public static final int T__38=38;
    public static final int NTERMINAL=5;
    public static final int T__39=39;
    public static final int RESERVEDT=13;
    public static final int ELEMENT=6;
    public static final int ALTERNATIVE=7;
    public static final int ATSOUT=19;
    public static final int OTHERT=17;
    public static final int STRING=21;

    // delegates
    // delegators


        public graalParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public graalParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return graalParser.tokenNames; }
    public String getGrammarFileName() { return "/home/luis/AnGEMC/src/grammarGrammar/graal.g"; }


    public static class grammar_sq_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "grammar_sq"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:7:1: grammar_sq : ( rule )+ ;
    public final graalParser.grammar_sq_return grammar_sq() throws RecognitionException {
        graalParser.grammar_sq_return retval = new graalParser.grammar_sq_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        graalParser.rule_return rule1 = null;



        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:8:3: ( ( rule )+ )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:8:5: ( rule )+
            {
            root_0 = (Object)adaptor.nil();

            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:8:5: ( rule )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ID) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:8:6: rule
            	    {
            	    pushFollow(FOLLOW_rule_in_grammar_sq58);
            	    rule1=rule();

            	    state._fsp--;

            	    adaptor.addChild(root_0, rule1.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "grammar_sq"

    public static class rule_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "rule"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:14:1: rule : i= identifier atributs ':' alternatives[flag] ';' -> { flag==1 }? ^( TERMINAL $i alternatives ) -> ^( NTERMINAL $i alternatives atributs ) ;
    public final graalParser.rule_return rule() throws RecognitionException {
        graalParser.rule_return retval = new graalParser.rule_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal3=null;
        Token char_literal5=null;
        graalParser.identifier_return i = null;

        graalParser.atributs_return atributs2 = null;

        graalParser.alternatives_return alternatives4 = null;


        Object char_literal3_tree=null;
        Object char_literal5_tree=null;
        RewriteRuleTokenStream stream_28=new RewriteRuleTokenStream(adaptor,"token 28");
        RewriteRuleTokenStream stream_29=new RewriteRuleTokenStream(adaptor,"token 29");
        RewriteRuleSubtreeStream stream_atributs=new RewriteRuleSubtreeStream(adaptor,"rule atributs");
        RewriteRuleSubtreeStream stream_alternatives=new RewriteRuleSubtreeStream(adaptor,"rule alternatives");
        RewriteRuleSubtreeStream stream_identifier=new RewriteRuleSubtreeStream(adaptor,"rule identifier");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:15:3: (i= identifier atributs ':' alternatives[flag] ';' -> { flag==1 }? ^( TERMINAL $i alternatives ) -> ^( NTERMINAL $i alternatives atributs ) )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:15:5: i= identifier atributs ':' alternatives[flag] ';'
            {
            pushFollow(FOLLOW_identifier_in_rule80);
            i=identifier();

            state._fsp--;

            stream_identifier.add(i.getTree());
            pushFollow(FOLLOW_atributs_in_rule82);
            atributs2=atributs();

            state._fsp--;

            stream_atributs.add(atributs2.getTree());
            char_literal3=(Token)match(input,28,FOLLOW_28_in_rule84);  
            stream_28.add(char_literal3);

            int flag = ((i!=null?i.id:null).charAt(0) >= 'A' && (i!=null?i.id:null).charAt(0) <= 'Z')  ? 1 : 0; 
            pushFollow(FOLLOW_alternatives_in_rule97);
            alternatives4=alternatives(flag);

            state._fsp--;

            stream_alternatives.add(alternatives4.getTree());
            char_literal5=(Token)match(input,29,FOLLOW_29_in_rule100);  
            stream_29.add(char_literal5);



            // AST REWRITE
            // elements: atributs, i, alternatives, alternatives, i
            // token labels: 
            // rule labels: retval, i
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
            RewriteRuleSubtreeStream stream_i=new RewriteRuleSubtreeStream(adaptor,"rule i",i!=null?i.tree:null);

            root_0 = (Object)adaptor.nil();
            // 17:29: -> { flag==1 }? ^( TERMINAL $i alternatives )
            if ( flag==1 ) {
                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:17:45: ^( TERMINAL $i alternatives )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TERMINAL, "TERMINAL"), root_1);

                adaptor.addChild(root_1, stream_i.nextTree());
                adaptor.addChild(root_1, stream_alternatives.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 18:12: -> ^( NTERMINAL $i alternatives atributs )
            {
                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:18:15: ^( NTERMINAL $i alternatives atributs )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(NTERMINAL, "NTERMINAL"), root_1);

                adaptor.addChild(root_1, stream_i.nextTree());
                adaptor.addChild(root_1, stream_alternatives.nextTree());
                adaptor.addChild(root_1, stream_atributs.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "rule"

    public static class identifier_return extends ParserRuleReturnScope {
        public String id;
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "identifier"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:21:1: identifier returns [String id] : ID ;
    public final graalParser.identifier_return identifier() throws RecognitionException {
        graalParser.identifier_return retval = new graalParser.identifier_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ID6=null;

        Object ID6_tree=null;

        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:23:3: ( ID )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:23:5: ID
            {
            root_0 = (Object)adaptor.nil();

            ID6=(Token)match(input,ID,FOLLOW_ID_in_identifier161); 
            ID6_tree = (Object)adaptor.create(ID6);
            adaptor.addChild(root_0, ID6_tree);

             retval.id = (ID6!=null?ID6.getText():null); 

            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "identifier"

    public static class atributs_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "atributs"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:26:1: atributs : (i= ats )? ( 'returns' o= ats )? -> ^( ATSIN ( $i)? ) ^( ATSOUT ( $o)? ) ;
    public final graalParser.atributs_return atributs() throws RecognitionException {
        graalParser.atributs_return retval = new graalParser.atributs_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal7=null;
        graalParser.ats_return i = null;

        graalParser.ats_return o = null;


        Object string_literal7_tree=null;
        RewriteRuleTokenStream stream_30=new RewriteRuleTokenStream(adaptor,"token 30");
        RewriteRuleSubtreeStream stream_ats=new RewriteRuleSubtreeStream(adaptor,"rule ats");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:3: ( (i= ats )? ( 'returns' o= ats )? -> ^( ATSIN ( $i)? ) ^( ATSOUT ( $o)? ) )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:5: (i= ats )? ( 'returns' o= ats )?
            {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:6: (i= ats )?
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==31) ) {
                alt2=1;
            }
            switch (alt2) {
                case 1 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:6: i= ats
                    {
                    pushFollow(FOLLOW_ats_in_atributs181);
                    i=ats();

                    state._fsp--;

                    stream_ats.add(i.getTree());

                    }
                    break;

            }

            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:12: ( 'returns' o= ats )?
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==30) ) {
                alt3=1;
            }
            switch (alt3) {
                case 1 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:14: 'returns' o= ats
                    {
                    string_literal7=(Token)match(input,30,FOLLOW_30_in_atributs186);  
                    stream_30.add(string_literal7);

                    pushFollow(FOLLOW_ats_in_atributs190);
                    o=ats();

                    state._fsp--;

                    stream_ats.add(o.getTree());

                    }
                    break;

            }



            // AST REWRITE
            // elements: o, i
            // token labels: 
            // rule labels: retval, o, i
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
            RewriteRuleSubtreeStream stream_o=new RewriteRuleSubtreeStream(adaptor,"rule o",o!=null?o.tree:null);
            RewriteRuleSubtreeStream stream_i=new RewriteRuleSubtreeStream(adaptor,"rule i",i!=null?i.tree:null);

            root_0 = (Object)adaptor.nil();
            // 27:34: -> ^( ATSIN ( $i)? ) ^( ATSOUT ( $o)? )
            {
                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:37: ^( ATSIN ( $i)? )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(ATSIN, "ATSIN"), root_1);

                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:45: ( $i)?
                if ( stream_i.hasNext() ) {
                    adaptor.addChild(root_1, stream_i.nextTree());

                }
                stream_i.reset();

                adaptor.addChild(root_0, root_1);
                }
                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:50: ^( ATSOUT ( $o)? )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(ATSOUT, "ATSOUT"), root_1);

                // /home/luis/AnGEMC/src/grammarGrammar/graal.g:27:59: ( $o)?
                if ( stream_o.hasNext() ) {
                    adaptor.addChild(root_1, stream_o.nextTree());

                }
                stream_o.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "atributs"

    public static class ats_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "ats"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:30:1: ats : '[' variable ( ',' variable )* ']' -> ( variable )+ ;
    public final graalParser.ats_return ats() throws RecognitionException {
        graalParser.ats_return retval = new graalParser.ats_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal8=null;
        Token char_literal10=null;
        Token char_literal12=null;
        graalParser.variable_return variable9 = null;

        graalParser.variable_return variable11 = null;


        Object char_literal8_tree=null;
        Object char_literal10_tree=null;
        Object char_literal12_tree=null;
        RewriteRuleTokenStream stream_32=new RewriteRuleTokenStream(adaptor,"token 32");
        RewriteRuleTokenStream stream_31=new RewriteRuleTokenStream(adaptor,"token 31");
        RewriteRuleTokenStream stream_33=new RewriteRuleTokenStream(adaptor,"token 33");
        RewriteRuleSubtreeStream stream_variable=new RewriteRuleSubtreeStream(adaptor,"rule variable");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:31:3: ( '[' variable ( ',' variable )* ']' -> ( variable )+ )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:31:5: '[' variable ( ',' variable )* ']'
            {
            char_literal8=(Token)match(input,31,FOLLOW_31_in_ats229);  
            stream_31.add(char_literal8);

            pushFollow(FOLLOW_variable_in_ats231);
            variable9=variable();

            state._fsp--;

            stream_variable.add(variable9.getTree());
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:31:18: ( ',' variable )*
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( (LA4_0==32) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:31:20: ',' variable
            	    {
            	    char_literal10=(Token)match(input,32,FOLLOW_32_in_ats235);  
            	    stream_32.add(char_literal10);

            	    pushFollow(FOLLOW_variable_in_ats237);
            	    variable11=variable();

            	    state._fsp--;

            	    stream_variable.add(variable11.getTree());

            	    }
            	    break;

            	default :
            	    break loop4;
                }
            } while (true);

            char_literal12=(Token)match(input,33,FOLLOW_33_in_ats243);  
            stream_33.add(char_literal12);



            // AST REWRITE
            // elements: variable
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 31:41: -> ( variable )+
            {
                if ( !(stream_variable.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_variable.hasNext() ) {
                    adaptor.addChild(root_0, stream_variable.nextTree());

                }
                stream_variable.reset();

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ats"

    public static class variable_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "variable"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:34:1: variable : ID ID ;
    public final graalParser.variable_return variable() throws RecognitionException {
        graalParser.variable_return retval = new graalParser.variable_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token ID13=null;
        Token ID14=null;

        Object ID13_tree=null;
        Object ID14_tree=null;

        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:35:3: ( ID ID )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:35:5: ID ID
            {
            root_0 = (Object)adaptor.nil();

            ID13=(Token)match(input,ID,FOLLOW_ID_in_variable263); 
            ID13_tree = (Object)adaptor.create(ID13);
            adaptor.addChild(root_0, ID13_tree);

            ID14=(Token)match(input,ID,FOLLOW_ID_in_variable265); 
            ID14_tree = (Object)adaptor.create(ID14);
            adaptor.addChild(root_0, ID14_tree);


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "variable"

    public static class alternatives_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "alternatives"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:37:1: alternatives[int flag] : elements[$flag] ( '|' elements[flag] )* -> ( ^( ALTERNATIVE elements ) )+ ;
    public final graalParser.alternatives_return alternatives(int flag) throws RecognitionException {
        graalParser.alternatives_return retval = new graalParser.alternatives_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal16=null;
        graalParser.elements_return elements15 = null;

        graalParser.elements_return elements17 = null;


        Object char_literal16_tree=null;
        RewriteRuleTokenStream stream_34=new RewriteRuleTokenStream(adaptor,"token 34");
        RewriteRuleSubtreeStream stream_elements=new RewriteRuleSubtreeStream(adaptor,"rule elements");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:38:3: ( elements[$flag] ( '|' elements[flag] )* -> ( ^( ALTERNATIVE elements ) )+ )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:38:5: elements[$flag] ( '|' elements[flag] )*
            {
            pushFollow(FOLLOW_elements_in_alternatives280);
            elements15=elements(flag);

            state._fsp--;

            stream_elements.add(elements15.getTree());
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:38:21: ( '|' elements[flag] )*
            loop5:
            do {
                int alt5=2;
                int LA5_0 = input.LA(1);

                if ( (LA5_0==34) ) {
                    alt5=1;
                }


                switch (alt5) {
            	case 1 :
            	    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:38:22: '|' elements[flag]
            	    {
            	    char_literal16=(Token)match(input,34,FOLLOW_34_in_alternatives284);  
            	    stream_34.add(char_literal16);

            	    pushFollow(FOLLOW_elements_in_alternatives286);
            	    elements17=elements(flag);

            	    state._fsp--;

            	    stream_elements.add(elements17.getTree());

            	    }
            	    break;

            	default :
            	    break loop5;
                }
            } while (true);



            // AST REWRITE
            // elements: elements
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 38:44: -> ( ^( ALTERNATIVE elements ) )+
            {
                if ( !(stream_elements.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_elements.hasNext() ) {
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:38:47: ^( ALTERNATIVE elements )
                    {
                    Object root_1 = (Object)adaptor.nil();
                    root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(ALTERNATIVE, "ALTERNATIVE"), root_1);

                    adaptor.addChild(root_1, stream_elements.nextTree());

                    adaptor.addChild(root_0, root_1);
                    }

                }
                stream_elements.reset();

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "alternatives"

    public static class elements_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "elements"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:41:1: elements[int flag] : ( element[$flag] )+ -> ( ^( ELEMENT element ) )+ ;
    public final graalParser.elements_return elements(int flag) throws RecognitionException {
        graalParser.elements_return retval = new graalParser.elements_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        graalParser.element_return element18 = null;


        RewriteRuleSubtreeStream stream_element=new RewriteRuleSubtreeStream(adaptor,"rule element");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:42:3: ( ( element[$flag] )+ -> ( ^( ELEMENT element ) )+ )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:42:5: ( element[$flag] )+
            {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:42:5: ( element[$flag] )+
            int cnt6=0;
            loop6:
            do {
                int alt6=2;
                int LA6_0 = input.LA(1);

                if ( ((LA6_0>=ID && LA6_0<=STRING)||(LA6_0>=35 && LA6_0<=36)) ) {
                    alt6=1;
                }


                switch (alt6) {
            	case 1 :
            	    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:42:5: element[$flag]
            	    {
            	    pushFollow(FOLLOW_element_in_elements313);
            	    element18=element(flag);

            	    state._fsp--;

            	    stream_element.add(element18.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt6 >= 1 ) break loop6;
                        EarlyExitException eee =
                            new EarlyExitException(6, input);
                        throw eee;
                }
                cnt6++;
            } while (true);



            // AST REWRITE
            // elements: element
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 42:21: -> ( ^( ELEMENT element ) )+
            {
                if ( !(stream_element.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_element.hasNext() ) {
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:42:24: ^( ELEMENT element )
                    {
                    Object root_1 = (Object)adaptor.nil();
                    root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(ELEMENT, "ELEMENT"), root_1);

                    adaptor.addChild(root_1, stream_element.nextTree());

                    adaptor.addChild(root_0, root_1);
                    }

                }
                stream_element.reset();

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "elements"

    public static class element_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "element"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:45:1: element[int flag] : ( ( '~' )? s= single ( multiplier )? -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 0 }? ^( TERMINAL $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 1 }? ^( TERMINALT $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 0 }? ^( NTERMINAL $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 1 }? ^( NTERMINALT $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 0 }? ^( RESERVED $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 1 }? ^( RESERVEDT $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 0 }? ^( SIGN $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 1 }? ^( SIGNT $s ( multiplier )? ) -> { til == 0 }? ^( OTHER $s ( multiplier )? ) -> { til == 1 }? ^( OTHERT $s ( multiplier )? ) -> single ( multiplier )? | ( ( '~' )? '(' alternatives[$flag] ')' ( multiplier )? ) -> { $flag==0 && til == 0}? ^( SEQUENCE alternatives ( multiplier )? ) -> { $flag==0 && til == 1}? ^( SEQUENCET alternatives ( multiplier )? ) -> { til == 0 }? ^( OTHER alternatives ( multiplier )? ) -> { til == 1 }? ^( OTHERT alternatives ( multiplier )? ) -> alternatives ( multiplier )? );
    public final graalParser.element_return element(int flag) throws RecognitionException {
        graalParser.element_return retval = new graalParser.element_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal19=null;
        Token char_literal21=null;
        Token char_literal22=null;
        Token char_literal24=null;
        graalParser.single_return s = null;

        graalParser.multiplier_return multiplier20 = null;

        graalParser.alternatives_return alternatives23 = null;

        graalParser.multiplier_return multiplier25 = null;


        Object char_literal19_tree=null;
        Object char_literal21_tree=null;
        Object char_literal22_tree=null;
        Object char_literal24_tree=null;
        RewriteRuleTokenStream stream_35=new RewriteRuleTokenStream(adaptor,"token 35");
        RewriteRuleTokenStream stream_36=new RewriteRuleTokenStream(adaptor,"token 36");
        RewriteRuleTokenStream stream_37=new RewriteRuleTokenStream(adaptor,"token 37");
        RewriteRuleSubtreeStream stream_single=new RewriteRuleSubtreeStream(adaptor,"rule single");
        RewriteRuleSubtreeStream stream_alternatives=new RewriteRuleSubtreeStream(adaptor,"rule alternatives");
        RewriteRuleSubtreeStream stream_multiplier=new RewriteRuleSubtreeStream(adaptor,"rule multiplier");
         int til = 0; 
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:3: ( ( '~' )? s= single ( multiplier )? -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 0 }? ^( TERMINAL $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 1 }? ^( TERMINALT $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 0 }? ^( NTERMINAL $s ( multiplier )? ) -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 1 }? ^( NTERMINALT $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 0 }? ^( RESERVED $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 1 }? ^( RESERVEDT $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 0 }? ^( SIGN $s ( multiplier )? ) -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 1 }? ^( SIGNT $s ( multiplier )? ) -> { til == 0 }? ^( OTHER $s ( multiplier )? ) -> { til == 1 }? ^( OTHERT $s ( multiplier )? ) -> single ( multiplier )? | ( ( '~' )? '(' alternatives[$flag] ')' ( multiplier )? ) -> { $flag==0 && til == 0}? ^( SEQUENCE alternatives ( multiplier )? ) -> { $flag==0 && til == 1}? ^( SEQUENCET alternatives ( multiplier )? ) -> { til == 0 }? ^( OTHER alternatives ( multiplier )? ) -> { til == 1 }? ^( OTHERT alternatives ( multiplier )? ) -> alternatives ( multiplier )? )
            int alt11=2;
            switch ( input.LA(1) ) {
            case 35:
                {
                int LA11_1 = input.LA(2);

                if ( (LA11_1==36) ) {
                    alt11=2;
                }
                else if ( ((LA11_1>=ID && LA11_1<=STRING)) ) {
                    alt11=1;
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 11, 1, input);

                    throw nvae;
                }
                }
                break;
            case ID:
            case STRING:
                {
                alt11=1;
                }
                break;
            case 36:
                {
                alt11=2;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 11, 0, input);

                throw nvae;
            }

            switch (alt11) {
                case 1 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:5: ( '~' )? s= single ( multiplier )?
                    {
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:5: ( '~' )?
                    int alt7=2;
                    int LA7_0 = input.LA(1);

                    if ( (LA7_0==35) ) {
                        alt7=1;
                    }
                    switch (alt7) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:6: '~'
                            {
                            char_literal19=(Token)match(input,35,FOLLOW_35_in_element347);  
                            stream_35.add(char_literal19);

                             til = 1; 

                            }
                            break;

                    }

                    pushFollow(FOLLOW_single_in_element356);
                    s=single();

                    state._fsp--;

                    stream_single.add(s.getTree());
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:35: ( multiplier )?
                    int alt8=2;
                    int LA8_0 = input.LA(1);

                    if ( ((LA8_0>=38 && LA8_0<=40)) ) {
                        alt8=1;
                    }
                    switch (alt8) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:47:36: multiplier
                            {
                            pushFollow(FOLLOW_multiplier_in_element359);
                            multiplier20=multiplier();

                            state._fsp--;

                            stream_multiplier.add(multiplier20.getTree());

                            }
                            break;

                    }



                    // AST REWRITE
                    // elements: s, s, multiplier, multiplier, multiplier, single, s, multiplier, s, multiplier, s, multiplier, s, s, s, multiplier, s, multiplier, multiplier, multiplier, multiplier, s
                    // token labels: 
                    // rule labels: retval, s
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);
                    RewriteRuleSubtreeStream stream_s=new RewriteRuleSubtreeStream(adaptor,"rule s",s!=null?s.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 48:8: -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 0 }? ^( TERMINAL $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==1 && (s!=null?s.id:null).charAt(0) >= 'A' && (s!=null?s.id:null).charAt(0) <= 'Z' && til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:48:91: ^( TERMINAL $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TERMINAL, "TERMINAL"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:48:106: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 49:8: -> { $s.flag==1 && $s.id.charAt(0) >= 'A' && $s.id.charAt(0) <= 'Z' && til == 1 }? ^( TERMINALT $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==1 && (s!=null?s.id:null).charAt(0) >= 'A' && (s!=null?s.id:null).charAt(0) <= 'Z' && til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:49:91: ^( TERMINALT $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(TERMINALT, "TERMINALT"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:49:107: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 50:10: -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 0 }? ^( NTERMINAL $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==1 && (s!=null?s.id:null).charAt(0) >= 'a' && (s!=null?s.id:null).charAt(0) <= 'z' && til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:50:93: ^( NTERMINAL $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(NTERMINAL, "NTERMINAL"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:50:109: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 51:36: -> { $s.flag==1 && $s.id.charAt(0) >= 'a' && $s.id.charAt(0) <= 'z' && til == 1 }? ^( NTERMINALT $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==1 && (s!=null?s.id:null).charAt(0) >= 'a' && (s!=null?s.id:null).charAt(0) <= 'z' && til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:51:119: ^( NTERMINALT $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(NTERMINALT, "NTERMINALT"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:51:136: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 52:10: -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 0 }? ^( RESERVED $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==0 && flag==0 && (s!=null?s.id:null).matches("\\w+") && til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:52:77: ^( RESERVED $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(RESERVED, "RESERVED"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:52:92: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 53:8: -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\w+\") && til == 1 }? ^( RESERVEDT $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==0 && flag==0 && (s!=null?s.id:null).matches("\\w+") && til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:53:75: ^( RESERVEDT $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(RESERVEDT, "RESERVEDT"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:53:91: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 54:10: -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 0 }? ^( SIGN $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==0 && flag==0 && (s!=null?s.id:null).matches("\\W+") && til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:54:77: ^( SIGN $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(SIGN, "SIGN"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:54:88: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 55:9: -> { $s.flag==0 && flag==0 && $s.id.matches(\"\\\\W+\") && til == 1 }? ^( SIGNT $s ( multiplier )? )
                    if ( (s!=null?s.flag:0)==0 && flag==0 && (s!=null?s.id:null).matches("\\W+") && til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:55:76: ^( SIGNT $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(SIGNT, "SIGNT"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:55:88: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 56:10: -> { til == 0 }? ^( OTHER $s ( multiplier )? )
                    if ( til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:56:27: ^( OTHER $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(OTHER, "OTHER"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:56:39: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 57:9: -> { til == 1 }? ^( OTHERT $s ( multiplier )? )
                    if ( til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:57:26: ^( OTHERT $s ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(OTHERT, "OTHERT"), root_1);

                        adaptor.addChild(root_1, stream_s.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:57:39: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 58:9: -> single ( multiplier )?
                    {
                        adaptor.addChild(root_0, stream_single.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:58:19: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_0, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                    }

                    retval.tree = root_0;
                    }
                    break;
                case 2 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:5: ( ( '~' )? '(' alternatives[$flag] ')' ( multiplier )? )
                    {
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:5: ( ( '~' )? '(' alternatives[$flag] ')' ( multiplier )? )
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:6: ( '~' )? '(' alternatives[$flag] ')' ( multiplier )?
                    {
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:6: ( '~' )?
                    int alt9=2;
                    int LA9_0 = input.LA(1);

                    if ( (LA9_0==35) ) {
                        alt9=1;
                    }
                    switch (alt9) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:7: '~'
                            {
                            char_literal21=(Token)match(input,35,FOLLOW_35_in_element654);  
                            stream_35.add(char_literal21);

                             til = 1; 

                            }
                            break;

                    }

                    char_literal22=(Token)match(input,36,FOLLOW_36_in_element661);  
                    stream_36.add(char_literal22);

                    pushFollow(FOLLOW_alternatives_in_element662);
                    alternatives23=alternatives(flag);

                    state._fsp--;

                    stream_alternatives.add(alternatives23.getTree());
                    char_literal24=(Token)match(input,37,FOLLOW_37_in_element665);  
                    stream_37.add(char_literal24);

                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:54: ( multiplier )?
                    int alt10=2;
                    int LA10_0 = input.LA(1);

                    if ( ((LA10_0>=38 && LA10_0<=40)) ) {
                        alt10=1;
                    }
                    switch (alt10) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:59:55: multiplier
                            {
                            pushFollow(FOLLOW_multiplier_in_element668);
                            multiplier25=multiplier();

                            state._fsp--;

                            stream_multiplier.add(multiplier25.getTree());

                            }
                            break;

                    }


                    }



                    // AST REWRITE
                    // elements: multiplier, alternatives, alternatives, alternatives, alternatives, multiplier, alternatives, multiplier, multiplier, multiplier
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 60:13: -> { $flag==0 && til == 0}? ^( SEQUENCE alternatives ( multiplier )? )
                    if ( flag==0 && til == 0) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:60:41: ^( SEQUENCE alternatives ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(SEQUENCE, "SEQUENCE"), root_1);

                        adaptor.addChild(root_1, stream_alternatives.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:60:66: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 61:13: -> { $flag==0 && til == 1}? ^( SEQUENCET alternatives ( multiplier )? )
                    if ( flag==0 && til == 1) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:61:41: ^( SEQUENCET alternatives ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(SEQUENCET, "SEQUENCET"), root_1);

                        adaptor.addChild(root_1, stream_alternatives.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:61:67: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 62:15: -> { til == 0 }? ^( OTHER alternatives ( multiplier )? )
                    if ( til == 0 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:62:32: ^( OTHER alternatives ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(OTHER, "OTHER"), root_1);

                        adaptor.addChild(root_1, stream_alternatives.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:62:54: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 63:16: -> { til == 1 }? ^( OTHERT alternatives ( multiplier )? )
                    if ( til == 1 ) {
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:63:33: ^( OTHERT alternatives ( multiplier )? )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot((Object)adaptor.create(OTHERT, "OTHERT"), root_1);

                        adaptor.addChild(root_1, stream_alternatives.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:63:56: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_1, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }
                    else // 64:16: -> alternatives ( multiplier )?
                    {
                        adaptor.addChild(root_0, stream_alternatives.nextTree());
                        // /home/luis/AnGEMC/src/grammarGrammar/graal.g:64:32: ( multiplier )?
                        if ( stream_multiplier.hasNext() ) {
                            adaptor.addChild(root_0, stream_multiplier.nextTree());

                        }
                        stream_multiplier.reset();

                    }

                    retval.tree = root_0;
                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "element"

    public static class multiplier_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "multiplier"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:67:1: multiplier : ( '*' | '+' | '?' );
    public final graalParser.multiplier_return multiplier() throws RecognitionException {
        graalParser.multiplier_return retval = new graalParser.multiplier_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token set26=null;

        Object set26_tree=null;

        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:68:3: ( '*' | '+' | '?' )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:
            {
            root_0 = (Object)adaptor.nil();

            set26=(Token)input.LT(1);
            if ( (input.LA(1)>=38 && input.LA(1)<=40) ) {
                input.consume();
                adaptor.addChild(root_0, (Object)adaptor.create(set26));
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "multiplier"

    public static class single_return extends ParserRuleReturnScope {
        public String id;
        public int flag;
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "single"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:73:1: single returns [String id,int flag] : (s= STRING ( '..' STRING )? | i= identifier ( atribs )? );
    public final graalParser.single_return single() throws RecognitionException {
        graalParser.single_return retval = new graalParser.single_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token s=null;
        Token string_literal27=null;
        Token STRING28=null;
        graalParser.identifier_return i = null;

        graalParser.atribs_return atribs29 = null;


        Object s_tree=null;
        Object string_literal27_tree=null;
        Object STRING28_tree=null;

        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:75:3: (s= STRING ( '..' STRING )? | i= identifier ( atribs )? )
            int alt14=2;
            int LA14_0 = input.LA(1);

            if ( (LA14_0==STRING) ) {
                alt14=1;
            }
            else if ( (LA14_0==ID) ) {
                alt14=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 14, 0, input);

                throw nvae;
            }
            switch (alt14) {
                case 1 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:75:5: s= STRING ( '..' STRING )?
                    {
                    root_0 = (Object)adaptor.nil();

                    s=(Token)match(input,STRING,FOLLOW_STRING_in_single854); 
                    s_tree = (Object)adaptor.create(s);
                    adaptor.addChild(root_0, s_tree);

                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:75:14: ( '..' STRING )?
                    int alt12=2;
                    int LA12_0 = input.LA(1);

                    if ( (LA12_0==41) ) {
                        alt12=1;
                    }
                    switch (alt12) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:75:15: '..' STRING
                            {
                            string_literal27=(Token)match(input,41,FOLLOW_41_in_single857); 
                            string_literal27_tree = (Object)adaptor.create(string_literal27);
                            adaptor.addChild(root_0, string_literal27_tree);

                            STRING28=(Token)match(input,STRING,FOLLOW_STRING_in_single859); 
                            STRING28_tree = (Object)adaptor.create(STRING28);
                            adaptor.addChild(root_0, STRING28_tree);


                            }
                            break;

                    }

                    retval.flag =0; retval.id =(s!=null?s.getText():null);

                    }
                    break;
                case 2 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:76:5: i= identifier ( atribs )?
                    {
                    root_0 = (Object)adaptor.nil();

                    pushFollow(FOLLOW_identifier_in_single871);
                    i=identifier();

                    state._fsp--;

                    adaptor.addChild(root_0, i.getTree());
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:76:18: ( atribs )?
                    int alt13=2;
                    int LA13_0 = input.LA(1);

                    if ( (LA13_0==31) ) {
                        alt13=1;
                    }
                    switch (alt13) {
                        case 1 :
                            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:76:18: atribs
                            {
                            pushFollow(FOLLOW_atribs_in_single873);
                            atribs29=atribs();

                            state._fsp--;

                            adaptor.addChild(root_0, atribs29.getTree());

                            }
                            break;

                    }

                     retval.id = (i!=null?i.id:null); retval.flag =1;

                    }
                    break;

            }
            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "single"

    public static class atribs_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "atribs"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:79:1: atribs : '[' var ( ',' var )? ']' -> ( var )+ ;
    public final graalParser.atribs_return atribs() throws RecognitionException {
        graalParser.atribs_return retval = new graalParser.atribs_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token char_literal30=null;
        Token char_literal32=null;
        Token char_literal34=null;
        graalParser.var_return var31 = null;

        graalParser.var_return var33 = null;


        Object char_literal30_tree=null;
        Object char_literal32_tree=null;
        Object char_literal34_tree=null;
        RewriteRuleTokenStream stream_32=new RewriteRuleTokenStream(adaptor,"token 32");
        RewriteRuleTokenStream stream_31=new RewriteRuleTokenStream(adaptor,"token 31");
        RewriteRuleTokenStream stream_33=new RewriteRuleTokenStream(adaptor,"token 33");
        RewriteRuleSubtreeStream stream_var=new RewriteRuleSubtreeStream(adaptor,"rule var");
        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:80:3: ( '[' var ( ',' var )? ']' -> ( var )+ )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:80:5: '[' var ( ',' var )? ']'
            {
            char_literal30=(Token)match(input,31,FOLLOW_31_in_atribs905);  
            stream_31.add(char_literal30);

            pushFollow(FOLLOW_var_in_atribs907);
            var31=var();

            state._fsp--;

            stream_var.add(var31.getTree());
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:80:13: ( ',' var )?
            int alt15=2;
            int LA15_0 = input.LA(1);

            if ( (LA15_0==32) ) {
                alt15=1;
            }
            switch (alt15) {
                case 1 :
                    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:80:15: ',' var
                    {
                    char_literal32=(Token)match(input,32,FOLLOW_32_in_atribs911);  
                    stream_32.add(char_literal32);

                    pushFollow(FOLLOW_var_in_atribs913);
                    var33=var();

                    state._fsp--;

                    stream_var.add(var33.getTree());

                    }
                    break;

            }

            char_literal34=(Token)match(input,33,FOLLOW_33_in_atribs918);  
            stream_33.add(char_literal34);



            // AST REWRITE
            // elements: var
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 80:30: -> ( var )+
            {
                if ( !(stream_var.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_var.hasNext() ) {
                    adaptor.addChild(root_0, stream_var.nextTree());

                }
                stream_var.reset();

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "atribs"

    public static class var_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "var"
    // /home/luis/AnGEMC/src/grammarGrammar/graal.g:83:1: var : ( ID | STRING | DOLARID );
    public final graalParser.var_return var() throws RecognitionException {
        graalParser.var_return retval = new graalParser.var_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token set35=null;

        Object set35_tree=null;

        try {
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:84:3: ( ID | STRING | DOLARID )
            // /home/luis/AnGEMC/src/grammarGrammar/graal.g:
            {
            root_0 = (Object)adaptor.nil();

            set35=(Token)input.LT(1);
            if ( (input.LA(1)>=ID && input.LA(1)<=DOLARID) ) {
                input.consume();
                adaptor.addChild(root_0, (Object)adaptor.create(set35));
                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "var"

    // Delegated rules


 

    public static final BitSet FOLLOW_rule_in_grammar_sq58 = new BitSet(new long[]{0x0000000000100002L});
    public static final BitSet FOLLOW_identifier_in_rule80 = new BitSet(new long[]{0x00000000D0000000L});
    public static final BitSet FOLLOW_atributs_in_rule82 = new BitSet(new long[]{0x0000000010000000L});
    public static final BitSet FOLLOW_28_in_rule84 = new BitSet(new long[]{0x0000001880300000L});
    public static final BitSet FOLLOW_alternatives_in_rule97 = new BitSet(new long[]{0x0000000020000000L});
    public static final BitSet FOLLOW_29_in_rule100 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_identifier161 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ats_in_atributs181 = new BitSet(new long[]{0x0000000040000002L});
    public static final BitSet FOLLOW_30_in_atributs186 = new BitSet(new long[]{0x0000000080000000L});
    public static final BitSet FOLLOW_ats_in_atributs190 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_31_in_ats229 = new BitSet(new long[]{0x0000000000100000L});
    public static final BitSet FOLLOW_variable_in_ats231 = new BitSet(new long[]{0x0000000300000000L});
    public static final BitSet FOLLOW_32_in_ats235 = new BitSet(new long[]{0x0000000000100000L});
    public static final BitSet FOLLOW_variable_in_ats237 = new BitSet(new long[]{0x0000000300000000L});
    public static final BitSet FOLLOW_33_in_ats243 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_variable263 = new BitSet(new long[]{0x0000000000100000L});
    public static final BitSet FOLLOW_ID_in_variable265 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_elements_in_alternatives280 = new BitSet(new long[]{0x0000000400000002L});
    public static final BitSet FOLLOW_34_in_alternatives284 = new BitSet(new long[]{0x0000001880300000L});
    public static final BitSet FOLLOW_elements_in_alternatives286 = new BitSet(new long[]{0x0000000400000002L});
    public static final BitSet FOLLOW_element_in_elements313 = new BitSet(new long[]{0x0000001880300002L});
    public static final BitSet FOLLOW_35_in_element347 = new BitSet(new long[]{0x0000000880300000L});
    public static final BitSet FOLLOW_single_in_element356 = new BitSet(new long[]{0x000001C000000002L});
    public static final BitSet FOLLOW_multiplier_in_element359 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_35_in_element654 = new BitSet(new long[]{0x0000001000000000L});
    public static final BitSet FOLLOW_36_in_element661 = new BitSet(new long[]{0x0000001880300000L});
    public static final BitSet FOLLOW_alternatives_in_element662 = new BitSet(new long[]{0x0000002000000000L});
    public static final BitSet FOLLOW_37_in_element665 = new BitSet(new long[]{0x000001C000000002L});
    public static final BitSet FOLLOW_multiplier_in_element668 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_multiplier0 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_single854 = new BitSet(new long[]{0x0000020000000002L});
    public static final BitSet FOLLOW_41_in_single857 = new BitSet(new long[]{0x0000000000200000L});
    public static final BitSet FOLLOW_STRING_in_single859 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_identifier_in_single871 = new BitSet(new long[]{0x0000000080000002L});
    public static final BitSet FOLLOW_atribs_in_single873 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_31_in_atribs905 = new BitSet(new long[]{0x0000000000700000L});
    public static final BitSet FOLLOW_var_in_atribs907 = new BitSet(new long[]{0x0000000300000000L});
    public static final BitSet FOLLOW_32_in_atribs911 = new BitSet(new long[]{0x0000000000700000L});
    public static final BitSet FOLLOW_var_in_atribs913 = new BitSet(new long[]{0x0000000200000000L});
    public static final BitSet FOLLOW_33_in_atribs918 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_var0 = new BitSet(new long[]{0x0000000000000002L});

}